<!-- /* Description for file.
 * 添加寻访List
 * @copyright     Copyright 2008-2010, PHInfo Services Inc. (http://www.phinfoservices.com)
 * @package       ues
 * @subpackage    ues/app/views/resources
 * @since         ues
 * @version       V0.0.1
 * @modifiedby   会兵2011年0707
 * @lastmodified  会兵2011年0707
 */
 -->

<?php
echo $html->css ( 'jquery-validate/css/screen' );
echo $html->css ( 'style' );
echo $html->css ( 'tab' );
//echo $javascript->link ( 'jquery' );
?>

<script type="text/javascript">
var IND = IND1 = COM = '';
//添加验证
$(document).ready(function() {

	$.validator.setDefaults({
		submitHandler: function(form) {
			form.submit();
		}
	});

	$("#VisitorlistAddForm").validate({
		rules: {
		"data[Visitorlist][keywords]":{
			required: false,string:true,stringMinLength:0,stringMaxLength:20
		},
		visitorlistfile:{
			required: true,excel:true
		},
		"data[Visitorlist][name]":{
			required: false,string:true,stringMinLength:0,stringMaxLength:20
		},
		"data[Visitorlist][allowperson]":{
			required: false,alowsome:true,stringMinLength:0,stringMaxLength:20
		}
		},
		messages:{maxitem:{required: "请输入"}},
		focusInvalid:false,
		onkeyup:false,
		errorPlacement:function(error, element){error.appendTo(element.parent());}
	});
});
//验证结束
</script>

<script type="text/javascript">
//行业二级菜单
$(document).ready(function(){
	$("#VisitorlistIndustry1").change(function(){
		var IndustryDroptoplist = $(this).val();
		if(IndustryDroptoplist!="")
		{
			$("#VisitorlistIndustry").val($("#VisitorlistIndustry1 option:selected").text() + "_");
			$.post("<?php echo ROOT_WEB_PATH; ?>/industries/industriesQuery/",{
				Industry : $(this).val()
			},
			function(data,textStatus){
				$("#VisitorlistIndustry2:eq(0)>option").remove();
				$(data).find("aaa").each(function(){
					//	 alert($(this).attr("name"));
					$("#VisitorlistIndustry2:eq(0)").append("<option></option>");
					$("#VisitorlistIndustry2:eq(0)>option:last").val($(this).attr("name")).html($(this).text());
				});
			});
			
			$.post("<?php echo ROOT_WEB_PATH; ?>/companymanages/getCompany/",{
				Industry : $("#VisitorlistIndustry1 option:selected").text()
			},
			function(data,textStatus){
				$("#VisitorlistCompany:eq(0)>option").remove();
				$("#VisitorlistCompany:eq(0)").append("<option></option>");
				$("#VisitorlistCompany:eq(0)>option:last").val("").html("不限");
				$(data).find("aaa").each(function(){
					$("#VisitorlistCompany:eq(0)").append("<option></option>");
					$("#VisitorlistCompany:eq(0)>option:last").val($(this).text()).html($(this).text());
				});
			});
		}
		else
		{
			$.post("<?php echo ROOT_WEB_PATH; ?>/companymanages/getCompany/",{
				Industry : ''
			},
			function(data,textStatus){
				$("#VisitorlistCompany:eq(0)>option").remove();
				$("#VisitorlistCompany:eq(0)").append("<option></option>");
				$("#VisitorlistCompany:eq(0)>option:last").val("").html("不限");
				$(data).find("aaa").each(function(){
					$("#VisitorlistCompany:eq(0)").append("<option></option>");
					$("#VisitorlistCompany:eq(0)>option:last").val($(this).text()).html($(this).text());
				});
			});
			$("#VisitorlistIndustry2:eq(0)>option").remove();
			$("#VisitorlistIndustry2:eq(0)").append("<option></option>");
			$("#VisitorlistIndustry2:eq(0)>option:last").val("").html("不选");
			$("#VisitorlistIndustry").val("");
		}
	});
	$("#VisitorlistIndustry2").change(function(){
		var IndustryDroptoplist = $(this).val();
		if(IndustryDroptoplist!="")
		{
			$("#VisitorlistIndustry").val($("#VisitorlistIndustry1 option:selected").text() + "_" + $("#VisitorlistIndustry2 option:selected").text());
			$.post("<?php echo ROOT_WEB_PATH; ?>/companymanages/getCompany/",{
				Industry : $("#VisitorlistIndustry2 option:selected").text()
			},
			function(data,textStatus){
				$("#VisitorlistCompany:eq(0)>option").remove();
				$("#VisitorlistCompany:eq(0)").append("<option></option>");
				$("#VisitorlistCompany:eq(0)>option:last").val("").html("不限");
				$(data).find("aaa").each(function(){
					$("#VisitorlistCompany:eq(0)").append("<option></option>");
					$("#VisitorlistCompany:eq(0)>option:last").val($(this).text()).html($(this).text());
				});
			});
		}
		else
		{
			$("#VisitorlistIndustry").val($("#VisitorlistIndustry1 option:selected").text() + "_");
			$.post("<?php echo ROOT_WEB_PATH; ?>/companymanages/getCompany/",{
				Industry : $("#VisitorlistIndustry1 option:selected").text()
			},
			function(data,textStatus){
				$("#VisitorlistCompany:eq(0)>option").remove();
				$("#VisitorlistCompany:eq(0)").append("<option></option>");
				$("#VisitorlistCompany:eq(0)>option:last").val("").html("不限");
				$(data).find("aaa").each(function(){
					$("#VisitorlistCompany:eq(0)").append("<option></option>");
					$("#VisitorlistCompany:eq(0)>option:last").val($(this).text()).html($(this).text());
				});
			});
		}
	});

	//现在公司选择
	$("#VisitorlistCompany").change(function(){
		$("#visitorrecordsCompany").val($(this).val());
	});
	$('#searchbutton').click(function(){
		var SC = $('#searchCompany').val();
		var NowIND = $("#VisitorlistIndustry1 option:selected").val();
		var NowIND1 = $("#VisitorlistIndustry2 option:selected").val();
		if(COM == ''){
			COM = getCOM();
		}
		if(IND!=NowIND || IND1!=NowIND1){
			IND = NowIND;
			IND1 = NowIND1;
			COM = getCOM();
		}
		if(COM=='')	return;
		var C_ary = COM.split('|#|');
		$("#VisitorlistCompany:eq(0)>option").remove();
		$("#VisitorlistCompany:eq(0)").append("<option></option>");
		$("#VisitorlistCompany:eq(0)>option:last").val("").html("不限");
		for(var i=0;i<C_ary.length;i++){
			var v = C_ary[i];
			if(v=='') continue;
			if(SC=='' || v.indexOf(SC.toUpperCase())!=-1 || v.indexOf(SC.toLowerCase())!=-1){
				$("#VisitorlistCompany:eq(0)").append("<option></option>");
				$("#VisitorlistCompany:eq(0)>option:last").val(v).html(v);
			}
		}
	});
	function getCOM(){
		var N_com = '';
		$('#VisitorlistCompany option').each(function(){
			N_com += $(this).val()+"|#|";
		});
		return N_com;
	}

	//职位二级菜单
	$("#VisitorlistPosition1").change(function(){
		var IndustryDroptoplist = $(this).val();
		if(IndustryDroptoplist!="")
		{
			$("#VisitorlistPosition").val($("#VisitorlistPosition1 option:selected").text() + "_");
			$.post("<?php echo ROOT_WEB_PATH; ?>/positions/getPosition/",{
				Position : $(this).val()
			},
			function(data,textStatus){
				$("#VisitorlistPosition2:eq(0)>option").remove();
				$(data).find("aaa").each(function(){
					//	 alert($(this).attr("name"));
					$("#VisitorlistPosition2:eq(0)").append("<option></option>");
					$("#VisitorlistPosition2:eq(0)>option:last").val($(this).attr("name")).html($(this).text());
				});
			});
		}
		else
		{
			$("#VisitorlistPosition2:eq(0)>option").remove();
			$("#VisitorlistPosition2:eq(0)").append("<option></option>");
			$("#VisitorlistPosition2:eq(0)>option:last").val("").html("不选");
			$("#VisitorlistPosition").val("");
		}
	});
	$("#VisitorlistPosition2").change(function(){
		var IndustryDroptoplist = $(this).val();
		if(IndustryDroptoplist!="")
		{
			$("#VisitorlistPosition").val($("#VisitorlistPosition1 option:selected").text() + "_" + $("#VisitorlistPosition2 option:selected").text());
		}
		else
		{
			$("#VisitorlistPosition").val($("#VisitorlistPosition1 option:selected").text() + "_");
		}
	});


	//职能二级菜单

	$("#VisitorlistProfessional1").change(function(){
		var CompetencyDroptoplist = $(this).val();
		if(CompetencyDroptoplist!="")
		{
			$("#VisitorlistCompetency").val($("#VisitorlistProfessional1 option:selected").text() + "_");
			$.post("<?php echo ROOT_WEB_PATH; ?>/competencies/getcompetencies/",{
				Competency : $(this).val()
			},function(data,textStatus){
				$("#VisitorlistProfessional2:eq(0)>option").remove();
				$(data).find("aaa").each(function(){
					//	 alert($(this).attr("name"));
					$("#VisitorlistProfessional2:eq(0)").append("<option></option>");
					$("#VisitorlistProfessional2:eq(0)>option:last").val($(this).attr("name")).html($(this).text());
					$("#VisitorlistProfessional3:eq(0)>option").remove();
					$("#VisitorlistProfessional3:eq(0)").append("<option></option>");
					$("#VisitorlistProfessional3:eq(0)>option:last").val("").html("不选");
				});
			});
		}
		else
		{
			$("#VisitorlistProfessional2:eq(0)>option").remove();
			$("#VisitorlistProfessional2:eq(0)").append("<option></option>");
			$("#VisitorlistProfessional2:eq(0)>option:last").val("").html("不选");
			$("#VisitorlistProfessional3:eq(0)>option").remove();
			$("#VisitorlistProfessional3:eq(0)").append("<option></option>");
			$("#VisitorlistProfessional3:eq(0)>option:last").val("").html("不选");
			$("#VisitorlistCompetency").val("");
		}
	});


	//职能三层字段 级联菜单 //

	$("#VisitorlistProfessional2").change(function(){
		var list = $(this).val();
		if(list!="")
		{
			$("#VisitorlistCompetency").val($("#VisitorlistProfessional1 option:selected").text() + "_" + $("#VisitorlistProfessional2 option:selected").text() + "_");
			$.post("<?php echo ROOT_WEB_PATH; ?>/competencies/getcompetencies/",{
				Competency : $(this).val()
			},function(data,textStatus){
				$("#VisitorlistProfessional3:eq(0)>option").remove();
				$(data).find("aaa").each(function(){
					//	 alert($(this).attr("name"));
					$("#VisitorlistProfessional3:eq(0)").append("<option></option>");
					$("#VisitorlistProfessional3:eq(0)>option:last").val($(this).attr("name")).html($(this).text());
				});
			});
		}
		else
		{
			$("#VisitorlistProfessional3:eq(0)>option").remove();
			$("#VisitorlistProfessional3:eq(0)").append("<option></option>");
			$("#VisitorlistProfessional3:eq(0)>option:last").val("").html("不选");
			$("#VisitorlistCompetency").val($("#VisitorlistProfessional1 option:selected").text() + "_");
		}
	});
	$("#VisitorlistProfessional3").change(function(){
		var list = $(this).val();
		if(list!="")
		{
			if($("#VisitorlistProfessional1 option:selected").text()!="不选"&&$("#VisitorlistProfessional1 option:selected").text()!="不限")
			$("#VisitorlistCompetency").val($("#VisitorlistProfessional1 option:selected").text() + "_" + $("#VisitorlistProfessional2 option:selected").text() + "_" + $("#VisitorlistProfessional3 option:selected").text());
			else
			$("#VisitorlistCompetency").val("");
		}
		else
		{
			if($("#VisitorlistProfessional1 option:selected").text()!="不选"&&$("#VisitorlistProfessional2 option:selected").text()!="不限")
			$("#VisitorlistCompetency").val($("#VisitorlistProfessional1 option:selected").text() + "_" + $("#VisitorlistProfessional2 option:selected").text() + "_");
			else
			$("#VisitorlistCompetency").val("");
		}
	});
});

//打开用户选择框
$(function()
{
	$("#allowpersons").click(function(){
		$(".toolbarStyle").toggle();
	});
	$("#closeallowperson").click(function(){
		$(".toolbarStyle").toggle();
	});
	$("#closeallowperson").click(function(){
		$(".toolbarStyle").attr('style').attr('display').val('none');
	});

});

//选择用户提交
$(function()
{
	$("#addallowperson").click(function(){
		getDelStr();
		$(".toolbarStyle").toggle();
	});
});

//用来将选中的用户拼接起来
function getDelStr() {
	var delArr = $(":checkbox:checked");
	if(delArr.length==0)
	{
		alert("请选择用户!");
		return;
	}
	var str = "";
	for(var i=0;i<delArr.length;i++) {
		var del = delArr[i].value;
		str += del;
		str += ",";
	}
	$("#VisitorlistAllowperson").val(str);
}
</script>
<style>
.input{float:left;}
</style>
<!-- 当前位置-->
<div id="tabmenubar">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td class="tabmenubartitle1"><?php echo  __('YourPosition');//您现在的位置：?></td>
		<td class="tabmenubartitle2"><?php echo __('Visitor Management');//一级目录
echo '>';echo __('Visitorlist');//一级目录
										   echo '>';?>
									<?php echo $html->tag('span', __('Visitorlist Add',true));//当前操作地用span加粗?> 						  
		</td>
	</tr>
</table>
</div>
<!-- 当前位置-->

<div class="toolbarStyle" style="display:none">
	<?php 
	foreach ($users as $eachrecord)
	{
		echo $form->checkbox($eachrecord['User']['username'], array('value' => $eachrecord['User']['username']));
		echo $eachrecord['User']['username'];
	}
	?>
<table width="100%" cellspacing="0" cellpadding="0" border="0" style="text-align: left">
	<tr>
		<td width="50"></td>
		<td width="100"><?php echo $form->button('确定',array('class'=>'oksubmit','id'=>'addallowperson'));?>  <!-- __('reset', true)取消-->
		<td width="100"><?php echo $form->button('关闭',array('class'=>'cancelbutton','id'=>'closeallowperson'));?>  <!-- __('reset', true)取消-->
	</tr>
</table>
</div>

<?php echo $form->create('Visitorlist',array('action'=>'add','type'=> 'post','enctype'=>'multipart/form-data'));?>

<div class="tabflex">
<fieldset><legend><?php __('Visitorlist Add');?></legend>
<table width="100%" cellspacing="0" cellpadding="0" border="0"
	style="text-align: left">
	<!--当前行业下拉-->
	<tr>
		<td></td>
		<td><?php __('行业');?>:</td>
		<td colspan="2">
		<?php 
		echo $form->input('nowindustry',array('label'=>false,'id'=>'VisitorlistIndustry','style'=>"width:32%;"))."&nbsp;";
		$options = array();
		foreach($industrylist as $eachrecord)
		{
			$options[$eachrecord['Industry']['id']] = $eachrecord['Industry']['name'];
		}
		echo $form->input('industry1',array('empty' =>'不选','options'=>$options,'label'=>false,'div'=>false,'class'=>'TextBoxE1'));
				?>
		<?php echo $form->input('industry2',array('options'=>array('0'=>'不选'),'label'=>false,'div'=>false,'class'=>'TextBoxE1'));		
				?>
		</td>
		<?php 
		echo $form->hidden('industry');
		?>
		</tr>
		<!--现在公司下拉-->
		<tr>
		<td></td>
		<td><?php __('公司');?>:</td>
		<td colspan="2">
		<?php 
		echo $form->input('nowCompany',array('label'=>false,'id'=>'visitorrecordsCompany','readonly'=>true,'style'=>"width:32%;"))."&nbsp;";
		$options = array();
		foreach($companymanagelist as $eachrecord)
		{
			$options[$eachrecord['Companymanage']['name']] = $eachrecord['Companymanage']['name'];
		}
		echo $form->input('company',array('empty' =>'不选','options'=>$options,'label'=>false,'div'=>false,'class'=>'TextBoxE1'));
		?>
		<input type="text" id = 'searchCompany' style='width:80px;'>
		<input type="button" id="searchbutton" value="查">
		</td>
		</tr>
		<tr>
		<td></td>
		<td><?php __('职能');?>:</td>
		<!--职能下拉-->
		<td colspan="2">
		<?php 
		echo $form->input('nowcompetency',array('label'=>false,'id'=>'VisitorlistCompetency','readonly'=>true,'style'=>"width:32%;"))."&nbsp;";
		$options = array();
		foreach($competencylist as $eachrecord)
		{
			$options[$eachrecord['Competency']['id']] = $eachrecord['Competency']['name'];
		}
		echo $form->input('professional1',array('empty' =>'不选','options'=>$options,'label'=>false,'div'=>false,'class'=>'TextBoxE1'));
				?>

		<?php echo $form->input('professional2',array('options'=>array('0'=>'不选'),'label'=>false,'div'=>false,'class'=>'TextBoxE1'));		
				?>

		<?php echo $form->input('professional3',array('options'=>array('0'=>'不选'),'label'=>false,'div'=>false,'class'=>'TextBoxE1'));		
				?>
		</td>
		<?php 
		echo $form->hidden('competency');
		?>
		</tr>
		<tr>
		<td></td>
		<td><?php __('职位');?>:</td>
		<!--现在职位下拉-->
		<td colspan="2">
		<?php 
		echo $form->input('nowposition',array('label'=>false,'id'=>'VisitorlistPosition','readonly'=>true,'style'=>"width:32%;"))."&nbsp;";
		$options = array();
		foreach($positionlist as $eachrecord)
		{
			$options[$eachrecord['Position']['id']] = $eachrecord['Position']['name'];
		}
		echo $form->input('position1',array('empty' =>'不选','options'=>$options,'label'=>false,'div'=>false,'class'=>'TextBoxE1'));
				?>
		<?php echo $form->input('position2',array('options'=>array('0'=>'不选'),'label'=>false,'div'=>false,'class'=>'TextBoxE1'));		
				?>
		</td>
		<?php 
		echo $form->hidden('position');
		?>
		<!--现工作地区下拉-->
		</tr>
		<tr>
		<td></td>
		<td><?php __('关键字');?>:</td>
		<td colspan="2">
		<?php 	
		echo $form->input('keywords',array('label'=>false,'class'=>'TextBoxE1'));
		?> 
		</td>
		</tr>
		<tr>
		<!--年龄-->
		<td></td>
		<td><?php __('上传excel');?>:<font color="red">*</font></td>
		<td colspan="2">
			<?php 	
			echo $form->file('visitorlistfile',array('name'=>'visitorlistfile','label'=>false,'size'=>80));
			?> 
		</td>
		</tr>
		<tr>
		<!--工作电话-->
		<td></td>
		<td><?php __('修改文件名为');?>:</td>
		<td colspan="2">
			<?php 	
			echo $form->input('name',array('label'=>false,'class'=>'TextBoxE1'));
			?> 
		</td>
		</tr>
		<tr>
		<!--电子邮箱-->
		<td width="5%"></td>
		<td width="10%"><?php __('允许查看人');?>:</td>
		<td width="15%">
			<?php 	
				echo $form->input('allowperson',array('label'=>false,'div'=>false,'class'=>'TextBoxE1'));?>
		</td>
		<td>		 	
			<?php 	echo $form->button('允许人',array('class'=>'oksubmit','id'=>'allowpersons'));
			?> 
		</td>
		</tr>
	
</table>
</fieldset>
</div>
<table width="100%" cellspacing="0" cellpadding="0" border="0" style="text-align: left">
	<tr>
		<td width="50"></td>
		<td width="100"><?php echo $form->button('确定',array('type'=>'submit','class'=>'oksubmit'));?>  <!-- __('reset', true)取消-->
		<td width="100"><?php echo $form->button('重置',array('type'=>'reset','class'=>'resetsubmit'));?>  <!-- __('reset', true)取消-->
		</td>
	</tr>
</table>
<?php echo $form->end();?>


